/*
 * Copyright (c) 2011, 张达林
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of SlotBoard nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package cc.gpai.util.slotboard.example;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JSlider;

import cc.gpai.util.slotboard.StandardSignal;
import cc.gpai.util.slotboard.Slot;
import cc.gpai.util.slotboard.SlotBoard;


@SuppressWarnings("rawtypes")
public class GridExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setLayout(new GridLayout(3,3));
		JSlider[] sliders = new JSlider[9];
		StandardSignal[] signals = new StandardSignal[9];
		Slot[] slots = new Slot[9];
		for(int i=0;i<9;i++){
			int x = i%3+1;
			int y = i/3+1;
			String str = ""+x+" "+y;
			StandardSignal signal = new StandardSignal(str);
			JSlider slider = new JSlider();
			Slot slot = new SliderSlot(str,slider);
			slider.addChangeListener(signal.listener);
			signals[i]=signal;
			sliders[i]=slider;
			slots[i]=slot;
			frame.add(slider);
			SlotBoard.addSlot(slot);
		}
		String[][] array1=new String[][]{//signal slot,upward
				new String[]{"1 1","0 0"},new String[]{"2 1","0 0"},new String[]{"3 1","0 0"},
				new String[]{"1 2","1 1"},new String[]{"2 2","2 1"},new String[]{"3 2","3 1"},
				new String[]{"1 3","1 2"},new String[]{"2 3","2 2"},new String[]{"3 3","3 2"}
		};
		String[][] array2=new String[][]{//signal slot,to left
				new String[]{"1 1","0 0"},new String[]{"2 1","1 1"},new String[]{"3 1","2 1"},
				new String[]{"1 2","0 0"},new String[]{"2 2","1 2"},new String[]{"3 2","2 2"},
				new String[]{"1 3","0 0"},new String[]{"2 3","1 3"},new String[]{"3 3","2 3"}
		};
		
		for(String[] str:array1)
			SlotBoard.connect(str[0], str[1]);
		for(String[] str:array2)
			SlotBoard.connect(str[0], str[1]);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(320, 240);
		frame.setVisible(true);
	}

}